package com.gdlgxy.oa.controller;


import com.gdlgxy.oa.bean.FareList;
import com.gdlgxy.oa.service.FareServer;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class FareDelCtrl extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 根据传入的编号删除记录
        // 获取学生与其对应的删除记录的编号
        int Sno = Integer.parseInt(request.getParameter("Sno"));
        int Fno = Integer.parseInt(request.getParameter("Fno"));
        System.out.println("controller:要删除记录的学生为"+Sno+"删除的记录编号为"+Fno);

        // 获取链表
        FareList list = FareServer.list(Sno);
        // 删除节点
        list.fareDel(Fno);
        // 向数据库传递删除后链表
        // 删除成功就转发回学生链表
        if (FareServer.del(list)) {
            request.getRequestDispatcher("/fare/list?Sno="+Sno).forward(request, response);
        } else {
            // 删除失败
            request.getRequestDispatcher("/error.html").forward(request, response);
        }
    }
}
